﻿@using BootstrapBlazor.Components
@using TrackSystem.Entities.Dtos.Sensor
@using TrackSystem.Entities.Extensions


<h5>@(sensor.Description ??= "无描述")</h5>
<br />
<p>端口号: @sensor.Channel.Name</p>

<Divider class="mt-3 mb-3" />

<p>站地址: @sensor.Station</p>
@if (sensor.RO_Length == 0)
{
    <p>无只读寄存器</p>
}
else
{
    <p>只读寄存器: @sensor.RO_Address - @(sensor.RO_Address + sensor.RO_Length - 1)</p>
}

@if (sensor.RW_Length == 0)
{
    <p>无读写寄存器</p>
}
else
{
    <p>读写寄存器: @sensor.RW_Address - @(sensor.RW_Address + sensor.RW_Length - 1)</p>
}

<Divider class="mt-3 mb-3" />

<div class="d-flex">
    @{
        var chn = sensor.Channel;
         @if (chn != null)
        {
            <div class="ps-2">

                <div>@chn.Name (@chn.PortCategory.ToString() )</div>
                @if (chn.PortCategory == PortCategory.SRIAL)
                {
                    <div class="user-demo-address">
                        @($"串口: {chn.COMn},{chn.Baudrate},{chn.SerialParams}")
                    </div>
                }
                else
                {
                    <div class="user-demo-address">
                        @($"远程: {chn.Ip}:{chn.Port}")
                    </div>
                }

                @if (chn.PortCategory == PortCategory.UDP)
                {
                    <div class="user-demo-address">
                        @($"本地: {chn.localIp}:{chn.localPort}")
                    </div>
                }
                else
                {
                    <div class="user-demo-address">
                        <br />
                    </div>
                }
                <p>通信协议: @chn.Protocol.ToString()</p>
            </div>
        }
   }
</div>


@code{
    [Parameter]
    public SensorWithChannelDto sensor { get; set; }
}
